@include('layouts.header')
<div class="layui-layout layui-layout-admin">
    @include("layouts.header-menu")
    @include("layouts.menu")

    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div class="layui-form" style="padding: 15px;">
            <input type="hidden" name="info_id" id="info_id" value="{{ data_get($info, 'id') }}">
            <div class="layui-form-item">
                <label class="layui-form-label">姓名: <span style="color: red">*</span></label>
                <div class="layui-input-inline">
                    <input type="text" name="name" placeholder="姓名" value="{{ data_get($info, 'name') }}" lay-verify="required" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">类型: <span style="color: red">*</span></label>
                <div class="layui-input-inline">
                    <select name="type" >
                        <option value="">请选择</option>
                        <option value="实习律师" @if (data_get($info, 'type') == "实习律师") selected @endif>实习律师</option>
                        <option value="专职律师" @if (data_get($info, 'type') == "专职律师") selected @endif>专职律师</option>
                        <option value="高级律师" @if (data_get($info, 'type') == "高级律师") selected @endif>高级律师</option>
                        <option value="合伙人律师" @if (data_get($info, 'type') == "合伙人律师") selected @endif>合伙人律师</option>
                        <option value="全国优秀律师" @if (data_get($info, 'type') == "全国优秀律师") selected @endif>全国优秀律师</option>
                        <option value="专家律师" @if (data_get($info, 'type') == "专家律师") selected @endif>专家律师</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">工作地点: <span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="address" placeholder="工作地点" value="{{ data_get($info, 'address') }}" lay-verify="required" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">联系电话: <span style="color: red">*</span></label>
                <div class="layui-input-inline">
                    <input type="text" name="phone" placeholder="联系电话" value="{{ data_get($info, 'phone') }}" lay-verify="required" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">Email: <span style="color: red">*</span></label>
                <div class="layui-input-inline">
                    <input type="text" name="email" placeholder="Email" value="{{ data_get($info, 'email') }}" lay-verify="required" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">专业领域: <span style="color: red">*</span></label>
                <div class="layui-input-inline">
                    <input type="text" name="field" placeholder="专业领域" value="{{ data_get($info, 'field') }}" lay-verify="required" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">工作经历: <span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <textarea name="work_exp" id="work_exp" style="height: 607px;" placeholder="工作经历" class="layui-textarea">{{ data_get($info, "work_exp", "") }}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">个人荣誉: <span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <textarea name="honor" id="honor" style="height: 607px;" placeholder="个人荣誉" class="layui-textarea">{{ data_get($info, "honor", "") }}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">形象图片: <span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <div id="zhengshu_up_id">
                      <img src="{{ data_get($info, 'images') }}" width="100" height="100" />
                    </div>
                    <input type="hidden" name="images" id="zhengshu" value="{{ data_get($info, "images", "") }}" />
                    <button type="button" class="layui-btn" id="zhengshuBtn">上传图片</button>
                    图片规格：270 × 393
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="*">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
@include("layouts.footer")

<script type="text/javascript">
    layui.extend({
        tinymce: '/static/js/tinymce/tinymce'
    });
    layui.use(['form', 'element','layer', 'jquery', 'util', 'tinymce', 'upload'], function() {
        var layer = layui.layer,
            $ = layui.jquery,
            upload = layui.upload,
            form = layui.form;
        var t = layui.tinymce;

        var edit = t.render({
            elem: "#work_exp",
            automatic_uploads: false,
            images_upload_url: '/upload/images',
        },(opt, edit)=>{
            // 加载完成后回调 opt 是传入的所有参数
            // edit是当前编辑器实例，等同于t.get返回值
        });
        var edit2 = t.render({
            elem: "#honor",
            automatic_uploads: false,
            images_upload_url: '/upload/images',
        },(opt, edit)=>{
            // 加载完成后回调 opt 是传入的所有参数
            // edit是当前编辑器实例，等同于t.get返回值
        });

        form.on('submit(*)', function(forms){
            layer.load('loading', {time: 10000});
            forms.field['_token'] = '{{ csrf_token() }}';
            forms.field.work_exp = edit.getContent();
            forms.field.honor = edit2.getContent();
            $.post('/lawyer/create', forms.field, function (data){
                layer.closeAll('loading');
                if (data.code == 0){
                    layer.msg('保存成功', {icon:1});
                    setTimeout(function (){window.parent.location.reload()}, 2000);
                }else{
                    layer.msg(data.msg, {icon:2});
                }
            },'json');
            return false;
        });

        // 荣誉证书
        upload.render({
            elem: "#zhengshuBtn",
            url: '/common/uploads/images',
            filed: 'file',
            accept: 'images',
            data: {
                '_token': '{{ csrf_token() }}'
            },
            acceptMime: 'image/jpeg, image/jpg, image/png, image/gif',
            exts: 'jpg|png|jpeg|gif',
            auto: true,
            size: 1024 * 1024 * 2,
            multiple: false,
            number: 1,
            done: function(res, index, upload) {
                if (res.code != 0) {
                    layer.msg(res.msg, {icon: 2});
                }else{
                    $("#zhengshu").val(res.body.src);
                    $("#zhengshu_up_id").html("");
                    var _html = '<img src="'+res.body.src+'" width=100 height=100 />';
                    $("#zhengshu_up_id").append(_html);
                }
            }

        });

    });
</script>